unit uSceneInfo;

interface

uses uScene, Types, Graphics;

type
  TSceneInfo = class(TScene)
  private
    FDown: Boolean;
    M, B: TPoint;
  public
    ObjID: Integer;
    Back, WinBG, CmdOK, CmdOKD: TBitmap;
    procedure Render; override;
    procedure KeyDown(var Key: Word); override;
    constructor Create;
    destructor Destroy; override;
    procedure Timer; override;
    procedure MouseMove(X, Y: Integer); override; 
    procedure MouseUp(Button: TMouseBtn); override;
    procedure MouseDn(Button: TMouseBtn); override;
  end;
  
implementation

uses SysUtils, uSceneGame, uGraph, uScenes, uBorder, uUtils, uSprites;

{ TSceneInfo }

procedure TSceneInfo.MouseUp(Button: TMouseBtn);
begin
  FDown := False;  
  if (Button = mbLeft) and
    PointInRect(M.X, M.Y, B.X, B.Y, CmdOK.Width, CmdOK.Height) then
  begin
    Scenes.Scene := SceneGame;  
  end;
  Scenes.Render;
end;

procedure TSceneInfo.MouseDn(Button: TMouseBtn);
begin
  if (Button = mbLeft) and
    PointInRect(M.X, M.Y, B.X, B.Y, CmdOK.Width, CmdOK.Height) then
      FDown := True;  
  Scenes.Render;  
  FDown := False;  
end;

constructor TSceneInfo.Create;  
var
  Path: string;
const
  P = 'Data\Images\Window\';  
begin
  FDown := False;
  Path := ExtractFilePath(ParamStr(0));
  Back := TBitmap.Create;
  WinBG := TBitmap.Create;
  WinBG.LoadFromFile(Path + P + 'Back.bmp');
  with TBorder.Create(Path + P) do begin
    Make(WinBG);
    Free;
  end;
  CmdOK := TBitmap.Create;
  CmdOK.LoadFromFile(Path + P + 'BtnOK.bmp');
  CmdOKD := TBitmap.Create;
  CmdOKD.LoadFromFile(Path + P + 'BtnOKD.bmp');
end;

destructor TSceneInfo.Destroy;
begin
  CmdOK.Free;
  CmdOKD.Free;
  WinBG.Free;
  Back.Free;
  inherited;
end;

procedure TSceneInfo.KeyDown(var Key: Word);
begin
  case Key of
    27, 32: 
        begin
          Scenes.Scene := SceneGame;
          Scenes.Render;
        end;  
  end;
end;

procedure TSceneInfo.MouseMove(X, Y: Integer);
begin
  M.X := X;
  M.Y := Y;
end;

procedure TSceneInfo.Render;
begin
  Graph.Surface.Assign(Back);
  with Graph.Surface.Canvas do
  begin
    B.X := ((ScreenWidth * TileSize) div 2);
    B.Y := ((ScreenHeight * TileSize) div 2) - (WinBG.Height div 2);
    Draw(B.X - (WinBG.Width div 2), B.Y, WinBG);

    Draw(((ScreenWidth * TileSize) div 2) - 
      (Sprite[spObj][ObjID].Width div 2), B.Y + 20, 
        Sprite[spObj][ObjID]); 

    B.X := B.X - (CmdOK.Width div 2);
    B.Y := B.Y + (WinBG.Height - (CmdOK.Height * 2));
    if FDown then Draw(B.X, B.Y, CmdOKD) else Draw(B.X, B.Y, CmdOK); 
  end;
  Graph.Render;
end;

procedure TSceneInfo.Timer;
begin
  inherited;

end;

end.
